package pen_exam.Three60_2023_11_11;

import java.util.Scanner;

public class Class02_QuickWrong {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        int[] arr = new int[n];
        String[] s1 = sc.nextLine().split(" ");
        for (int i = 0; i < n; i++) {
            arr[i] = Integer.parseInt(s1[i]);
        }
        int k = Integer.parseInt(sc.nextLine());
        String[] s2 = sc.nextLine().split(" ");
        int[] f = new int[k];
        for (int i = 0; i < k; i++) {
            f[i] = Integer.parseInt(s2[i]);
        }
        int[] res =  func(arr,f);
        if(n >= 2){
            for (int i = 0; i < n - 1; i++) {
                System.out.print(res[i] + " ");
            }
            System.out.print(res[n - 1]);
        }else{
            System.out.print(res[0]);
        }
    }
    public static int[] func(int[] arr,int[] f){
        int[] temp = new int[arr.length];
        for (int i = 0; i < f.length; i++) {
            System.out.println(arr);
            int num = f[i];
            int index = 0;
            for (int j = 0; j < arr.length ; j++) {
                if(arr[j] < num){
                    temp[index++] = arr[j];
                }
            }
            for (int j = 0; j < arr.length ; j++) {
                if(arr[j] == num){
                    temp[index++] = num;
                }
            }
            for (int j = 0; j < arr.length ; j++) {
                if(arr[j] > num){
                    temp[index++] = arr[j];
                }
            }
            for (int j = 0; j < arr.length; j++) {
                arr[j] = temp[j];
            }
        }
        return  arr;
    }
}
